<template>
  <div class="row">
    <div class="col-4 mb-4" v-for="column in columnList" :key="column.id">
      <div class="card h-100 shadow-sm">
      <div class="card-body text-center">
        <img class="card-img-top" :src="column.avatar" :alt="column.title" srcset="" style="width: 150px;
    border-radius: 50%"/>
        <h5 class="card-title">{{ column.title }}</h5>
      <p class="card-text text-left">{{ column.description }}</p>
      <a href="#" class="btn btn-outline-primary">进去专栏</a>
      </div>
      </div>
    </div>
  </div>
</template>
<script lang="ts">
import { computed, defineComponent, PropType } from 'vue';
export interface ColumnProps {
  id: number;
  title: string;
  avatar?: string;
  description: string;
}
export default defineComponent({
  name: 'ColumnList',
  props: {
    list: {
      type: Array as PropType<ColumnProps[]>,
      required: true
    }
  },
  setup (props) {
    const columnList = computed(() => {
      return props.list.map(colnum => {
        if (!colnum.avatar) {
          colnum.avatar = require('@/assets/column.jpg')
        }
        return colnum
      })
    })
    return {
      columnList
    }
  }
});
</script>
